//获取Token参数
	var Request = new Object();
	Request = GetRequest();
	var token= Request['Token'];
	
	//页面初始条件
	var chargeLevel=0;
	var chargeCode='';
	var year='';
	var cMon=0;
	var cCharge='';
	var cName='';
	var steps;
	var stepIndex=-1;
	
	//饼图数据
	var qtiplist=[];
	var xTitle='';
	var TuTitle='';
	
	//下拉菜单ID
	var mId;
	var ScrollTmr;
	
    $('.mb').hide();
	$('.datagrid-sort-icon').hide();
  	
$(document).ready(function(){
//	$('.panel-tool').prepend('<a class="menu-icon icon-pie"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
	//添加图表工具栏按钮
	$('.panel-title').css(' vertical-align','middle');
	$('.panel-tool').css('padding-right','5px');
	$('.panel-tool').prepend('<a id="windowClose"  iconCls="icon-no" onclick=closeWin() />');
	$('.panel-tool').prepend('<a id="panelPie" iconCls="icon-pie" onclick=changeTu("pie") />');
	$('.panel-tool').prepend('<a id="panelBar" iconCls="icon-bar" onclick=changeTu("bar") />');
	$('.panel-tool').prepend('<a id="panelLine" iconCls="icon-line" onclick=changeTu("line") />');
	
	$('#windowClose').linkbutton({  
	});  
	$('#panelPie').linkbutton({  
	});  
	$('#panelBar').linkbutton({  
	});  
	$('#panelLine').linkbutton({  
	});  
	//足迹按钮
	$('#mBack').splitbutton({  
        menu: '#mHistory'  
    }); 
	var grid=$('#grid').datagrid({
		width:'auto',
		height:'auto',
		fit:true,
		nowrap: false,
		striped: true,
		collapsible : false,
		singleSelect:true,		
		url:'action/report/chargeMon/list.json?Token=' + token,
			sortName: 'CHARGECODE',
			sortOrder: 'asc',
			remoteSort: false,
			loadMsg:'正在载入数据...',
			idField:'CHARGECODE',
			frozenColumns:[[{field:'CHARGENAME',title:'',width:139,sortable:true,align:'left',
	        	  formatter:function(value,rowData,rowIndex){
	        	  		var str='"onmonse('+"''"+','+"'"+(rowIndex)+"'"+')"';
	        	  		var d=""
	        	  		var id="R_"+rowIndex;
	        	  		if(rowData.CHRGELEAF!=null&&rowData.CHRGELEAF=='1')
	        	  		   d="<table style='border-width: 0px;width:100%;padding:0px;' onmouseover=showMenu('"+id+"') ><tr style='border-width: 0px' ><td style='border-width: 0px'><a style='float:left;'href='javascript:void(0)' >"+value +"</a></td><td style='border-width: 0px;width:30px;'><a style='float:right;' id="+id+" style='visibility:false;' href='javascript:void(0)' class='mb' onmouseover="+str+" ></a></td></tr></table>";
	        	  		else	
						   d= "<table style='border-width: 0px;width:100%;padding:0px;' onmouseover=showMenu('"+id+"') ><tr style='border-width: 0px'><td style='border-width: 0px'><a style='float:left;' href='javascript:void(0)' title='点击查看详细信息'>" + value + "</a></td><td style='border-width: 0px;width:30px;'><a  id="+id+" style='visibility:false;float:right;' href='javascript:void(0)' class='mb' onmouseover="+str+" ></a></td></tr></table>";
						if(value=='合计'){
							d="合计<a href='javascript:void(0)' id='amt' onmouseover='PbtnOnmover()' onclick="+'pieShow('+'"pie"'+')'+"></a>";
						}
						return d;
	        	  }
	          }]],
			columns:[[
			          {field:'JANUARY',
			        	  title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('01')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:center'>1月</a></span><span style='float:right;margin-top: 8px;'><a id='01' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('01','')></a></span></div>",
			        	  width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'FEBRUARY',
			        		  title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('02')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>2月</a></span><span style='float:right;margin-top: 8px;'><a id='02' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('02','')></a></span></div>",
			        		  width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'MARCH',
			        			  title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('03')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>3月</a></span><span style='float:right;margin-top: 8px;'><a id='03' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('03','')></a></span></div>",
			        			  width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'APRIL',
			        				  title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('04')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>4月</a></span><span style='float:right;margin-top: 8px;'><a id='04' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('04','')></a></span></div>",
			        				  width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'MAY',
			        				title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('05')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>5月</a></span><span style='float:right;margin-top: 8px;'><a id='05' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('05','')></a></span></div>",
			        				width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'JUNE',
			        				title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('06')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>6月</a></span><span style='float:right;margin-top: 8px;'><a id='06' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('06','')></a></span></div>",
			        				width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'JULY',
			        				title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('07')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>7月</a></span><span style='float:right;margin-top: 8px;'><a id='07' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('07','')></a></span></div>",
			        				width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'AUGUST',
			        				title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('08')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>8月</a></span><span style='float:right;margin-top: 8px;'><a id='08' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('08','')></a></span></div>",
			        				width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'SEPTEMBER',
			        				title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('09')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>9月</a></span><span style='float:right;margin-top: 8px;'><a id='09' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('09','')></a></span></div>",
			        				width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'OCTOBER',
			        				title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('10')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>10月</a></span><span style='float:right;margin-top: 8px;'><a id='10' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('10','')></a></span></div>",
			        				width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'NOVEMBER',
			        					title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('11')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>11月</a></span><span style='float:right;margin-top: 8px;'><a id='11' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('11','')></a></span></div>",
			        					width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}},
			          {field:'DECEMBER',
			        					title:"<div class='tCol' style='display: block;padding:0px;width:100%;' onmouseover=showMenu('12')><span style='float: left;width: 60%;'><a style='color:#1C879A;text-align:left'>12月</a></span><span style='float:right;margin-top: 8px;'><a id='12' style='float:right;' href='javascript:void(0)' class='mb'  onmouseover=onmonse('12','')></a></span></div>",
			        					width:100,sortable:true,align:'right',formatter:function(value,rowData,rowIndex){ return fmoney(value,2);}}
			          ]],
		pagination:true,
		rownumbers:true,
		showFooter:true,
		onBeforeLoad:function(param){
			//隐藏图表按钮
		    $('.mb').hide();
		    //隐藏列排序按钮
			$('.datagrid-sort-icon').hide();
			
			//设置第一列列头图片
			$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('background-image','url(images/chrgMonTitle.gif)');
			$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('width','139px');
//			$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('height','58px');
			$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('background-position','left -59px');
			
		},
		onLoadSuccess:function(data){
			//设置页面条件
            chargeLevel = data.chargeLevel;
            chargeCode =data.chargeCode;
            steps=data.steps;
            if(data.year!=null&&data.year.length>0){
	            year=data.year;
	            $("#YEAR").combobox('setText',year);
            }
            stepIndex=data.stepIndex;
            
            //绑定图表菜单
            $('.mb').menubutton({  
	              menu: '#mm'  
	          }); 
            $('#amt').menubutton({  
	              menu: '#mm'  
	          }); 
            //设置图表按钮隐藏
            $('.mb').hide();
			$('.btn').linkbutton({  
              plain:true  
              }); 
			$('.datagrid-sort-icon').hide();
			
			//显示导航
			showSteps(steps);
			
			//隐藏拉动框
			$('div.datagrid-view2>div.datagrid-body').css('overflow','hidden');
			
			//绑定网格拖动事件
			$('#grid').datagrid("columnMoving");
			
		},onDblClickRow:function(rowIndex,rowData){
			
		},onClickCell : function(rowIndex, field,
											value) {
										$('#grid').datagrid(
												'selectRow',rowIndex);
										var select = $('#grid').datagrid(
												'getSelected');
										//点击单位列
										if (field = 'CHARGENAME') {
											if(select.CHRGELEAF!='1'){
												var chargeCode = select.CHARGECODE;
												chargeLevel=1+chargeLevel;
												var rowName = select.CHARGENAME;
	                                            $('#grid').datagrid("options").pageNumber = 1;
	                                            $('#grid').datagrid({url: 'action/report/chargeMon/list.json?Token=' 
	                                            	            + token
																+ '&chargeCode='
																+ chargeCode
																+ '&chargeLevel='
																+ chargeLevel+'&year='+year,
	                                            'queryParams':{
	                                               'rowName':rowName,
	                                               'isNextLevel':'Y',
	                                               'rnd': Math.random()
	                                               }});
											}
										}
			}
	});
	// 初始化新增界面财政单位下拉框
	$("#YEAR").combobox({
	    url:'action/report/chargeMon/GETYEAR.json?Token=' +token+"&rnd="+Math.random(),
	    valueField:'id',
	    textField:'text',
	    panelHeight:'150px',
	    editable:false
	});
	$('#ChargeTree').combotree({
		url :'action/basic/charge/tree.json?Token=' + token+"&rnd="+Math.random(),
		editable:false,
		panelWidth:'300',
		        onDblClick: function(node)
				{
					//双击展开节点
					$('#ChargeTree').val(node.text);
					$(this).tree('toggle', node.target);
				},
				onClick: function(node)
				{
					$('#ChargeTree').val(node.text);
                 },onShowPanel:function()
         		{
         			$(this).combotree('panel').parent('.panel').css('border-bottom','#87cedb 3px solid');
         			$(this).combotree('panel').parent('.panel').css('border-left','#87cedb 3px solid');
         			$(this).combotree('panel').parent('.panel').css('border-right','#87cedb 3px solid');
         		}
         });
	$('.datagrid-sort-icon').hide();
	$('.fieldName').css('display','block');
	$('.fieldName').css('padding','1px');
	
	//设置第一列列头图片
	$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('background-image','url(images/chrgMonTitle.gif)');
	$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('width','139px');
//	$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('height','58px');
	$("div.datagrid-header-inner>table").find("td[field='CHARGENAME']").css('background-position','left -59px');
    });

//clearSelect("UserGrid")
//formatpagination("UserGrid")


//把信息放入回复留言页面
function inputdata(data)
{
	$("#txtuser").val(data.F_USER);
	$("#txtpwd").val(data.F_PWD);
	$("#txtmemo").val(data.F_MEMO);
	$("#txtid").val(data.F_ID);
	if (data.F_TYPE=="2" )
		$("#rdono").attr("checked","true");
	else
		$("#rdoyes").attr("checked","true");
}
//条件按条件查询
function QryConndition() 
{
	var rName='';
	chargeCode=$("#ChargeTree").val();
		if (chargeCode!=null&&chargeCode.length>0){
			rName=chargeCode.substring(1+chargeCode.indexOf(']',0),chargeCode.length);
			chargeCode=chargeCode.substring(1+chargeCode.indexOf('[',0),chargeCode.indexOf(']',0));
		}
	year=$("#YEAR").combobox('getText');	
$('#grid').datagrid("options").pageNumber = 1;
$('#grid').datagrid({url: 'action/report/chargeMon/list.json?Token=' 
    + token
	+ '&chargeCode='
	+ chargeCode
	+ '&year='+year,
'queryParams':{
'rowName':'项目：'+rName+' 年份：'+year,
'isQuery':'Y',	
'rnd': Math.random()
}});
}
//鼠标悬停图标按钮时触发
function onmonse(mon,chgrRow){

	       cMon=mon;
	       if(chgrRow!=null&&chgrRow.length!=0){
	    	   $('#grid').datagrid('selectRow',chgrRow);
			   var select = $('#grid').datagrid('getSelected');
			   cCharge=select.CHARGECODE;
			   cName=select.CHARGENAME;
			   $('#grid').datagrid('unselectAll');
	       }
}

function pieShow(type){
	var iUrl='';
	var title='';
	var xName='';
	var btData = 'Y' ;
	if(cMon!=null&&cMon.length!=0){
	    iUrl='action/report/chargeMon/getQtip.json?Token='+ token+'&groupType=month&chargeCode='+chargeCode+'&chargeLevel='+chargeLevel+'&month='+cMon+'&year='+year;
	    title=cMon+'月';
	    xName='项目';
	}
	else if(cCharge!=null&&cCharge.length!=0){
	    iUrl='action/report/chargeMon/getQtip.json?Token='+ token+'&groupType=charge&chargeCode='+cCharge+'&chargeLevel='+chargeLevel+'&year='+year;
	    title=cName;
	    xName='月份';
	}
	else{
		iUrl='action/report/chargeMon/getQtip.json?Token='+ token+'&groupType=charge&chargeLevel='+chargeLevel+'&chargeCode='+chargeCode+'&year='+year;
	    title='合计';
	    xName='月份';
	}
	if(iUrl!=null&&iUrl.length!=0){
		$.getJSON(iUrl+'&rnd='+ Math.random(),function(data){
				qtiplist=data.qtipData;
				if(qtiplist.length>0){
					if(type=='pie')
                    {
						for(i=0 ;i<qtiplist.length;i++)
						{
						    if(qtiplist[i].value<0)
						    {						    	
						    	btData = 'N' ;
						    	break;
						    }	
						}
						if(btData=='Y')
				    		pie(title,xName)
					    else
					      $.messager.alert('提示',"<h5>含有负数数据，不能生成饼图!</h5>");
                    }	
					if(type=='bar')
					  bar(title,xName);
					if(type=='line')
					  line(title,xName);	
				}
		});
	}
	cMon='';	
	cCharge='';
}
//鼠标离开图标按钮时触发
function PbtnOnmover(){
	cMon='';	
	cCharge='';
}

//饼图
function pie(title,xName)
{
	
	var char = {};
	xName=xTitle;
	TuTitle=title;
	char["xAxisName"]=xName;
	char["yAxisName"] = "收入";
	char["caption"] = title;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	var btData = 'Y' ;
	json["chart"]=char;
	json["data"]=data;
	//alert(char.yaxisname);
	$('#pie').window('open');
	$('#pie').window('maximize');
	var h=$('#outSide').height();
	var w=$('#outSide').width();
	$('#pie').css('width',w-4);
	$('#pie').css('height',h-34);
	$("div[class*='window']").not('.window-mask').css('width',w-4);
	$('.window-shadow').css('height',h-34);

	var myChart = new FusionCharts("javascript/fusioncharts/Pie2D.swf", "asdf", "100%", "100%", "0", "1");

    myChart.setJSONData(json);
    myChart.render("pie");
    
}

//柱状图
function bar(title,xName)
{
	var char = {};
	xName=xTitle;
	TuTitle=title;
	char["xAxisName"]=xName;
	char["yAxisName"] = "收入";
	char["caption"] = title;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	json["chart"]=char;
	json["data"]=data;

	$('#pie').window('open');
	$('#pie').window('maximize');
	var h=$('#outSide').height();
	var w=$('#outSide').width();
	$('#pie').css('width',w-4);
	$('#pie').css('height',h-34);
	$("div[class*='window']").not('.window-mask').css('width',w-4);
	$('.window-shadow').css('height',h-34);

	var myChart = new FusionCharts("javascript/fusioncharts/Column3D.swf", "asdf", "100%", "100%", "0", "1");

    myChart.setJSONData(json);
    myChart.render("pie");
}

//柱状图
function line(title,xName)
{
	var char = {};
	xName=xTitle;
	TuTitle=title;
	char["xAxisName"]=xName;
	char["yAxisName"] = "收入";
	char["caption"] = title;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	json["chart"]=char;
	json["data"]=data;

	$('#pie').window('open');
	$('#pie').window('maximize');
	var h=$('#outSide').height();
	var w=$('#outSide').width();
	$('#pie').css('width',w-4);
	$('#pie').css('height',h-34);
	$("div[class*='window']").not('.window-mask').css('width',w-4);
	$('.window-shadow').css('height',h-34);

	var myChart = new FusionCharts("javascript/fusioncharts/Line.swf", "asdf", "100%", "100%", "0", "1");

    myChart.setJSONData(json);
    myChart.render("pie");
}

function changeTu(title){
	var char = {};
	char["xAxisName"]=xTitle;
	char["yAxisName"] = "收入";
	char["caption"] = TuTitle;
	char["numberprefix"] = "￥";
	char["showborder"] = "1";
	char["numberScaleUnit"]="千,百万,十亿,万亿";
	var data = [qtiplist];
	var json ={};
	json["chart"]=char;
	json["data"]=data;
    var btData = 'Y' ;
    if(title=='line')
	    var myChart = new FusionCharts("javascript/fusioncharts/Line.swf", "asdf", "100%", "100%", "0", "1");
    else if(title=='pie')
    {
		
			for(i=0 ;i<qtiplist.length;i++)
			{
			    if(qtiplist[i].value<0)
			    {						    	
			    	btData = 'N' ;
			    	break ;
			    }	
			}
			if(btData=='Y')
	    		var myChart = new FusionCharts("javascript/fusioncharts/Pie2D.swf", "asdf", "100%", "100%", "0", "1");
	    	else
	    		$.messager.alert('提示',"<h5>含有负数数据，不能生成饼图!</h5>");
        	
    }
    else if(title=='bar')	
    	var myChart = new FusionCharts("javascript/fusioncharts/Column3D.swf", "asdf", "100%", "100%", "0", "1");
    
    myChart.setJSONData(json);
    myChart.render("pie");
}
//查询栏可视属性修改
function showQryPnl(type){
	if(type=='show'){
		$("#toolPnl").css('display','none');
		$("#toolPnl").hide('slow');
		$("#queryPnl").show('slow');
	}else if(type=='hide'){
		$("#queryPnl").hide('slow');
		$("#toolPnl").show('slow');
	}
}

//生成访问足迹
function showSteps(st){
	if(st!=null&&st.length>0){
		$("#mHistory").empty();
		for(i=(st.length-1);i>-1;i--){
        	var step=st[i];
        	$('#mHistory').menu('appendItem',{id:'step_'+i,text:step.stepName,name:i,
        		handler:function(){
        			var index=this.id.substring(1+this.id.indexOf('_',0),this.id.length);
        			toStep(index);
        		}
        	});
		}
		$('#mHistory').menu('appendItem',{id:'step_-1',text:'首页',
			handler:function(){
				toStep("-1");
			}
		});

	}

}

//左右添加足迹
function moveStep(lr){
	var rId=0;
	var aId=0;
	var name="";
	if(lr=='left'){
		if (startStep==0){
			$('#lbtn').hide();
		}else{
		rId=startStep+4;
        aId=startStep-1;
        startStep=startStep-1;
        var step=steps[aId];
    	name=step.stepName;	
    	$("#step_"+rId).remove();
    	$("#step").prepend('<a id="step_'+aId+'" class="step" onclick=toStep("'+aId+'")>'+name+'--></a>');
    	$('#rbtn').show();
		}	
	}
	if(lr=='right'){
		
		if ((startStep+5)>=steps.length){
		     $('#rbtn').hide();
		}else{
		rId=startStep;
        aId=startStep+5;
        startStep=startStep+1;
        var step=steps[aId];
    	name=step.stepName;	
    	$("#step_"+rId).remove();
    	$("#step").append('<a id="step_'+aId+'" class="step" onclick=toStep("'+aId+'")>-->'+name+'</a>');
    	$('#lbtn').show();
		}
	}
	
	if (startStep==0)
		$('#lbtn').hide();
	if ((startStep+5)>=steps.length)
		$('#rbtn').hide();
	
}

//跳转到足迹页面
function toStep(index){
	var rowName='';
	if(index>=0){
	   var step=steps[index];
	   chargeCode=step.chargeCode;
	   chargeLevel=step.chargeLevel;
	   rowName=step.rowName;
	   year=step.year;
	}else{
	   chargeCode="";
	   chargeLevel=0;
	   year="";
	}	
	$('#grid').datagrid("options").pageNumber = 1;
	$('#grid').datagrid({url: 'action/report/chargeMon/list.json?Token=' 
        + token
		+ '&chargeCode='
		+ chargeCode
		+ '&chargeLevel='
		+ chargeLevel+'&year='+year,
	'queryParams':{
	'isNextLevel':'Y',
	'isStep':'Y',
	'stepIndex':index,
	'rowName':rowName,
	'rnd': Math.random()
	}});
}

function fmoney(s, n)//将数字转换成逗号分隔的样式,保留两位小数s:value,n:小数位数   
{
	var flag = 1 ;
	rs='';
	if(s!=0)
	{	if(s<0)
		{
			flag = 0 ;
			s=-s;
		}
		n = n > 0 && n <= 20 ? n : 2;
		s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
		var l = s.split(".")[0].split("").reverse(),
		r = s.split(".")[1];
		t = "";
		for(i = 0; i < l.length; i ++ )
		{
		t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
		}
		rs=t.split("").reverse().join("") + "." + r;
	}
	if(flag==0)
		rs="-"+rs;
	return rs;
}
//重置查询条件
function clearQry(){
	$("#ChargeTree").combotree('setValue','');
	$("#YEAR").combo('setValue',year);
}
//鼠标悬停单元格显示对应图表按钮
function showMenu(id){
	if(id!=mId)
	   $(".mb").hide('slow');
	$("#"+id).show();
	mId=id;
}
//后退
function back(){
	var idx=stepIndex-1;
	if(idx>=0){
		   var step=steps[idx];
		   chargeCode=step.chargeCode;
		   chargeLevel=step.chargeLevel;
		   year=step.year;
		}else{
		   chargeCode="";
		   chargeLevel=0;
		   year="";
		}	
		$('#grid').datagrid("options").pageNumber = 1;
		$('#grid').datagrid({url: 'action/report/chargeMon/list.json?Token=' 
	        + token
			+ '&chargeCode='
			+ chargeCode
			+ '&chargeLevel='
			+ chargeLevel+'&year='+year,
		'queryParams':{
		'isNextLevel':'Y',
		'isStep':'Y',
		'stepIndex':idx,
		'rnd': Math.random()
		}});
}
//显示滚动条
function showScroll(){
	clearTimeout(ScrollTmr); 
	$('div.datagrid-view2>div.datagrid-body').css('overflow','auto');
}
//隐藏滚动条
function hideScroll(e,o){
	if(o.contains(event.toElement ) == false) 
		$('div.datagrid-view2>div.datagrid-body').css('overflow','hidden');
}

$.extend($.fn.datagrid.methods,{
	columnMoving: function(jq){
		return jq.each(function(){
			var target = this;
			var cells = $(this).datagrid('getPanel').find('div.datagrid-header td[field]');
			cells.draggable({
				revert:true,
				cursor:'pointer',
				edge:5,
				proxy:function(source){
					var p = $('<div class="tree-node-proxy tree-dnd-no" style="position:absolute;border:1px solid #ff0000"/>').appendTo('body');
					p.html($(source).text());
					p.hide();
					return p;
				},
				onBeforeDrag:function(e){
					e.data.startLeft = $(this).offset().left;
					e.data.startTop = $(this).offset().top;
				},
				onStartDrag: function(){
					$(this).draggable('proxy').css({
						left:-10000,
						top:-10000
					});
				},
				onDrag:function(e){
					$(this).draggable('proxy').show().css({
						left:e.pageX+15,
						top:e.pageY+15
					});
					return false;
				}
			}).droppable({
				accept:'td[field]',
				onDragOver:function(e,source){
					$(source).draggable('proxy').removeClass('tree-dnd-no').addClass('tree-dnd-yes');
					$(this).css('border-left','1px solid #ff0000');
				},
				onDragLeave:function(e,source){
					$(source).draggable('proxy').removeClass('tree-dnd-yes').addClass('tree-dnd-no');
					$(this).css('border-left',0);
				},
				onDrop:function(e,source){
					$(this).css('border-left',0);
					var fromField = $(source).attr('field');
					var toField = $(this).attr('field');
					setTimeout(function(){
						moveField(fromField,toField);
						$(target).datagrid();
						$(target).datagrid('columnMoving');
					},0);
				}
			});
			
			// move field to another location
			function moveField(from,to){
				var columns = $(target).datagrid('options').columns;
				var cc = columns[0];
				var c = _remove(from);
				if (c){
					_insert(to,c);
				}
				
				function _remove(field){
					for(var i=0; i<cc.length; i++){
						if (cc[i].field == field){
							var c = cc[i];
							cc.splice(i,1);
							return c;
						}
					}
					return null;
				}
				function _insert(field,c){
					var newcc = [];
					for(var i=0; i<cc.length; i++){
						if (cc[i].field == field){
							newcc.push(c);
						}
						newcc.push(cc[i]);
					}
					columns[0] = newcc;
				}
			}
		});
	}
});
//处理IE行高问题,IE真变态
function setIEHeight(tr,height){
	tr.find('td').css("height",height);
}

function closeWin(){
	$('#pie').window('close');
}